#!/bin/bash

# 处理 nginx 日志
NginxLogDir="/data/project/docker/nginx/logs"
Yesterday=`date -d "yesterday" +"%Y%m%d"`

# 将日志前一天的日志分割
mv "${NginxLogDir}/access.log" "${NginxLogDir}/access.log.${Yesterday}"
nginx -s reopen

#重载日志文件
#echo '' > "${NginxLogDir}/access.log"

# 保留的日志备份数
BackupDays=20
# 删除50天以前的日志,+${BackupDays}代表多少天前
find ${NginxLogDir} -mtime +${BackupDays} -name "access.log.*" -exec rm -rf {} \;

echo 'nginx log deal finished' $Yesterday